<?php

	header("Content-Type:text/html; charset=utf-8");
	

	/***********************用户注册模块*********************/

	//连接数据库 (引入)
	include("connect_db.php");

	$phone = $_REQUEST['phone'];  //从表单中获取到的数
	$nickname = $_REQUEST['nickname'];
	$password = $_REQUEST['pwd'];
	$sex = $_REQUEST['age'];
	$age = $_REQUEST['sex'];
	$address = $_REQUEST['address'];

	// $phone = $POST['phone'];  //从表单中获取到的数
	// $nickname = $POST['nickname'];
	// $password = $POST['pwd'];
	// $sex = $POST['age'];
	// $age = $POST['sex'];
	// $address = $POST['address'];


	//数据库查询
	$selectResult = mysql_query("SELECT * FROM user");
	$exits = false;
	//echo $exits.'<br/>';
	while($row =mysql_fetch_array($selectResult)){
		if($phone == $row['phone']){// 若果存在
			$exits = true;
			$register_res = array("register_res"=>false,"register_code"=>0);
			$json = json_encode($register_res);
			echo $json;
		}
	}
	if(!$exits){//否则  不存在 插入到数据库中
		$sql = "INSERT INTO user(phone,nickname,pwd,sex,age,address) VALUES(".$phone.",'".$nickname."',".$password.",'".$sex."',".$age.",'".$address."')";
		$success = mysql_query($sql);
		if($success){//数据插入成功
			$register_res = array("register_res"=>$success,"register_code"=>1002);
			$json = json_encode($register_res);
			echo $json;
		}else{//注册失败
			$register_res = array("register_res"=>$success,"register_code"=>1);
			$json = json_encode($register_res);
			echo $json;
		}
	}
		

	
	// 获得注册页面的input输入的信息
	// $phone = $_POST[$getPhone];  //从表单中获取到的数
	// $email = $_POST[$getEmail];
	// $nickName = $_POST[$getNickName];
	// $password = $_POST[$getPassword];
	// $re_password = $_POST[$getRepassword];
	// $sex = $_POST[$getSex];
	// $age = $_POST[$getAge];
	// $address = $_POST[$getAddress];


	// $phone = "18797547850";  //从表单中获取到的数
	// $email = "";
	// $username = '陈艳秋';
	// $password = "111111";
	// $sex = "女";
	// $age = 110;
	// $address = "厦门";

	// //数据插入数据库
	// if($phone && !$email){//用电话登陆

	// 	//判断手机号是否存在数据库中
	// 	$exits = mysql_query("SELECT * FROM user WHERE phone=".$phone);
	// 	if(!$exits){// 若果不存在，怎存入到数据库中
	// 		$sql = "INSERT INTO user(phone,username,pwd,sex,age,address) VALUES(".$phone.",'".$username."',".$password.",'".$sex."',".$age.",'".$address."')";
	// 	}else{
	// 		die('该用户已存在');
	// 	}
		
	// }else if($email && !$phone){
	// 	//判断手机号是否存在数据库中
	// 	$exits = mysql_query("SELECT * FROM user WHERE email=".$email);
	// 	if(!$exits){
	// 		$sql = "INSERT INTO user(email,username,pwd,sex,age,address) VALUES('".$email."','".$username."',".$password.",'".$sex."',".$age.",'".$address."')";
	// 	}else{
	// 		die('该用户已存在');
	// 	}
		
	// }

	// $getInsterRes = mysql_query($sql);

	// if(!$getInsterRes){
	// 	//die('Error'.mysql_error());

	// }else{
	// 	echo "数据插入成功！";
	// }


	// 关闭数据库
	mysql_close($link);

?>